package cn.tedu.tnt_sky.service.Impl;

import cn.tedu.tnt_sky.mapper.ArticlesTagMapper;
import cn.tedu.tnt_sky.mapper.TagsMapper;
import cn.tedu.tnt_sky.pojo.entity.Tags;
import cn.tedu.tnt_sky.pojo.vo.ObtainLabelVO;
import cn.tedu.tnt_sky.service.TagsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
* @author 17975
* @description 针对表【tags】的数据库操作Service实现
* @createDate 2023-08-19 13:17:07
*/
@Service
public class TagsServiceImpl implements TagsService{

    @Autowired
    TagsMapper tagsMapper;
    @Autowired
    ArticlesTagMapper articlesTagMapper;

    @Override
    public ObtainLabelVO obtainLabel() {
        HashMap<Integer, Integer> hashMap = new HashMap<>();
        HashMap<Integer, String> hashMap2 = new HashMap<>();
        //获取到标签的信息(集合)
        List<Tags> label = tagsMapper.getTags();
        //遍历数组获取标签id
        for (int i =0; i<label.size();i++){
            Long tagsId = label.get(i).getId();//标签id
            Long value = articlesTagMapper.tagsValueByTagsId(tagsId);
            hashMap.put(i, Math.toIntExact(value));//标签数量
            hashMap2.put(i, label.get(i).getName());//标签名称
        }
        //通过对应的set方法封装信息到ObtainLabelVO对象
        ObtainLabelVO obtainLabelVO = new ObtainLabelVO();
        obtainLabelVO.setValue(hashMap);
        obtainLabelVO.setName(hashMap2);
        //返回该对象实例
        return obtainLabelVO;
    }
}
